package com.srlg.app.controller;

import com.srlg.app.model.po.MediaFiles;
import com.srlg.app.model.po.Order;
import com.srlg.app.service.OrderService;
import com.srlg.common.req.R;
import io.swagger.v3.oas.annotations.ExternalDocumentation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @desc:
 * @author: srlg li
 * @date: 2023/12/2 23:58
 */
@Tag(
    name = "OrderControllerAPI",
    description = "order控制器接口",
    externalDocs = @ExternalDocumentation(
        description = "这是一个接口文档介绍",
        url = "https://www.srlg.com/"))
@RestController
@RequestMapping("order")
@RequiredArgsConstructor
public class OrderController {

    private final OrderService orderService;

    /**
     * 根据id查询订单
     *
     * @return
     */
    @Operation(
        summary = "查询全部文件",
        description = "查询全部文件信息，并返回响应结果信息",
        parameters = {@Parameter(name = "id", description = "订单id")},
        deprecated = false,
        responses = {
            @ApiResponse(
                responseCode = "200",
                description = "响应成功",
                content = @Content(
                    mediaType = MediaType.APPLICATION_JSON_VALUE,
                    schema = @Schema(
                        title = "Order模型",
                        description = "返回实体，Order",
                        anyOf = {R.class, MediaFiles.class})
                )
            )
        }
    )
    @RequestMapping("/getById")
    public Order getById(@RequestParam("id") Long id) {
        //根据id查询订单
        Order order = orderService.getById(id);
        return order;
    }

    /**
     * 创建订单
     *
     * @return
     */
    @RequestMapping("/create")
    public String create(@RequestBody Order order) {
        //创建订单
        orderService.create(order);
        return "success";
    }

    /**
     * 对订单进行支付
     *
     * @param id
     * @return
     */
    @RequestMapping("/pay")
    public String pay(@RequestParam("id") Long id) {
        //对订单进行支付
        orderService.pay(id);
        return "success";
    }

    /**
     * 对订单进行发货
     *
     * @param id
     * @return
     */
    @RequestMapping("/deliver")
    public String deliver(@RequestParam("id") Long id) {
        //对订单进行确认收货
        orderService.deliver(id);
        return "success";
    }

    /**
     * 对订单进行确认收货
     *
     * @param id
     * @return
     */
    @RequestMapping("/receive")
    public String receive(@RequestParam("id") Long id) {
        //对订单进行确认收货
        orderService.receive(id);
        return "success";
    }
}
